package initialize

import (
	"fmt"
	"github.com/go-redsync/redsync/v4"
	"github.com/go-redsync/redsync/v4/redis/goredis/v9"
	goredislib "github.com/redis/go-redis/v9"
	"go.uber.org/zap"
	"mxshop_srvs/inventory_srv/global"
)

//func InitRedis() {
//	redisAddr := fmt.Sprintf("%s:%d", global.ServerConfig.RedisInfo.Host, global.ServerConfig.RedisInfo.Port)
//	zap.S().Infof("Connecting to Redis: %s", redisAddr)
//	global.RedisClient = redis.NewClient(&redis.Options{
//		Addr: redisAddr,
//	})
//	global.LockClient = redislock.New(global.RedisClient)
//}

func InitRedisSync() {
	redisAddr := fmt.Sprintf("%s:%d", global.ServerConfig.RedisInfo.Host, global.ServerConfig.RedisInfo.Port)
	zap.S().Infof("Connecting to Redis: %s", redisAddr)

	global.RedisClient = goredislib.NewClient(&goredislib.Options{
		Addr: redisAddr,
	})
	pool := goredis.NewPool(global.RedisClient) // or, pool := redigo.NewPool(...)

	global.RedSync = redsync.New(pool)

}
